package com.projects.android.dto;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class MenuDTO {
	private int ID;
	private int IDRestaurant;
	private String Name;
	private ArrayList<FoodDTO> Foods;

	public String toString(){
		return Name;
	}
	
	public void initObject(JSONObject data) {
		try {
			ID = Integer.valueOf(data.getString("ID"));
			IDRestaurant = Integer.valueOf(data.getString("IDRestaurant"));
			Name = data.getString("Name");
			Foods = new ArrayList<FoodDTO>();
			JSONArray arrData = new JSONArray(data.getString("Foods"));
			// Loop for all reveived objects
			for (int i = 0; i < arrData.length(); i++) {
				JSONObject dataChild = (JSONObject) arrData.get(i);
				FoodDTO dto = new FoodDTO();
				dto.initObject(dataChild);
				Foods.add(dto);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			Log.e("Init MenuDTO", e.toString());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e("Init MenuDTO", e.toString());
		}
	}

	public int getID() {
		return ID;
	}

	public void setID(int iD) {
		ID = iD;
	}

	public int getIDRestaurant() {
		return IDRestaurant;
	}

	public void setIDRestaurant(int iDRestaurant) {
		IDRestaurant = iDRestaurant;
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public ArrayList<FoodDTO> getFoods() {
		return Foods;
	}

	public void setFoods(ArrayList<FoodDTO> foods) {
		Foods = foods;
	}
}
